package t1;

import java.io.FileInputStream;
import java.io.InputStream;

public class CustomClassLoader extends ClassLoader {
	// private Hashtable classes = new Hashtable();
	String name;

	public CustomClassLoader() {
		super(CustomClassLoader.class.getClassLoader());
//		this.name = arg0;
	}

	// public Class loadClass(String className) throws ClassNotFoundException {
	// return findClass(className);
	// }

	public Class findClass(String className) throws ClassNotFoundException {
		FileInputStream fi = null;
		try {
			System.out.println("CustomClassLoader finding class: " + className);
//			String path = className.replace('.', '/');
//			fi = new FileInputStream(CustomClassLoader.class.getClassLoader().getResourceAsStream(className));

			byte[] classBytes = new byte[fi.available()];
			fi.read(classBytes);
			return defineClass(className, classBytes, 0, classBytes.length);
		} catch (Exception e) {
			// We could not find the class, so indicate the problem with an
			// exception
			throw new ClassNotFoundException(className);
		} finally {
			if (null != fi) {
				try {
					fi.close();
				} catch (Exception e) {
				}
			}
		}
	}
}
